#ifndef CALIBRATIONIMAGESELECTORGUI_H
#define CALIBRATIONIMAGESELECTORGUI_H

#include <opencv2/highgui/highgui.hpp>
#include <vector>

#include "FindRectTarget.h"
#include "DataStructures.h"
#include "motiondetection.h"
#include "FindRectTarget.h"
#include "TargetCoverageCheck.hpp"

namespace idch {

    // guides the user in the calibration process
class CalibrationImageSelectorGUI
{
public:
    CalibrationImageSelectorGUI( MotionDetection *motion , int warmupFrames );
    ~CalibrationImageSelectorGUI();

    // processes the images and returns true if enough calibration targets have been found
    bool process( cv::Mat colorImg , cv::Mat depthImg );

    const std::vector<CalibrationLocation>& getTargets() const;

private:

    void saveImages();

    void setMessage( const char *message );

    // prints out a message telling the user its still warming up
    void doWarmUp();

    // extracts the target from the images
    bool doActive( cv::Mat colorImg , cv::Mat depthImg );

    // take the found targets and calibrate
    bool doCalibrate();

    // finds the target in the motion image, writes its state into 'target' and updates the small image with
    // feature extraction stuff
    bool findAndDrawTarget( cv::Mat& motionImg , RectPt &target , cv::Mat &smallImg , bool isDepth );

    void drawTarget( const RectPt& target , cv::Mat image ,  bool usedTarget );

    // how many frames it waits until it starts
    int warmupFrames;

    // how many frames have been processed
    int numFrames;

    // main window image buffer
    cv::Mat mainImg;

    // image buffers used for drawing stuff
    cv::Mat drawRGB;
    cv::Mat drawDepth;
    // temp image buffer
    cv::Mat tempRGB;
    cv::Mat tempSmallGray;

    // list of all the found calibration targets in both images
    std::vector<CalibrationLocation> targets;

    // finds pixels that are moving
    MotionDetection *motion;
    FindRectTarget findTarget;

    TargetCoverageCheck coverage;

    // how many images it has captures of the target
    int numCapturedImages;
};

}

#endif // CALIBRATIONIMAGESELECTORGUI_H
